package com.baoteng.rbspy.model.kind;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.baoteng.rbspy.annotation.JsoupProperty;
import com.baoteng.rbspy.model.response.quote.PrpCprofitFactors;
import com.baoteng.rbspy.util.JsoupUtil;
import com.google.common.collect.Lists;

/**
 * 
 * @author Administrator
 *
 */
public class BIPO {

	/**
	 * 条款期次
	 */
	@JsoupProperty(tag = "input[id=prpCmainCommon.clauseIssue]")
	String clauseIssue;

	/**
	 * 计费方式： 2--按日
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.shortRateFlag]")
	String shortRateFlag;
	/**
	 * 短期：
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.shortRate]")
	String shortRate;

	/**
	 * 币别： CNY
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.currency]")
	String currency;

	/**
	 * 特殊折扣申请：
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.preDiscount]")
	String preDiscount;

	/**
	 * 总标准保费：
	 */
	@JsoupProperty(tag = "input[id=sumBenchPremium]")
	Double sumBenchPremium;

	String strSumBenchPremium;
	
	/**
	 * 总折扣：
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.discount]")
	Double discount;

	/**
	 * 保费税合计：
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.sumPremium]")
	Double sumPremium;
	
	String strSumPremium;
	

	/**
	 * 总保费：
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.sumNetPremium]")
	Double sumNetPremium;

	String strSumNetPremium;
	/**
	 * 总税额：
	 */
	@JsoupProperty(tag = "input[id=prpCitemKind.sumTaxPremium]")
	Double sumTaxPremium;

	String strSumTaxPremium;
	
	/**
	 * 是否走平台缓存 
	 */
	Integer proposalCacheFlag=0;
	
	/**
	 * 平台查 询 码
	 */
	String biDemandNo;
	
	/**
	 * 查询时间
	 */
	String biDemandTime;
	
	List<KindPO> kinds;

	/**
	 * 商业险费率
	 */
	List<PrpCprofitFactors> factors;
	/**
	 * 连续未出险年数
	 */
	Integer noDamYearsBI=0;
	/**
	 * 商业险上年赔款(次)
	 */
	Integer lastDamagedBI=0;
	/**
	 * 商业险本年赔款(次)
	 */
	Integer thisDamagedBI=0;
	/**
	 * 商业险上年违法(次)
	 */
	Integer lastDamagedCI=0;
	public String getClauseIssue() {
		return clauseIssue;
	}

	public void setClauseIssue(String clauseIssue) {
		this.clauseIssue = clauseIssue;
	}

	public String getShortRateFlag() {
		return shortRateFlag;
	}

	public void setShortRateFlag(String shortRateFlag) {
		this.shortRateFlag = shortRateFlag;
	}

	public String getShortRate() {
		return shortRate;
	}

	public void setShortRate(String shortRate) {
		this.shortRate = shortRate;
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public String getPreDiscount() {
		return preDiscount;
	}

	public void setPreDiscount(String preDiscount) {
		this.preDiscount = preDiscount;
	}

	public Double getSumBenchPremium() {
		return sumBenchPremium;
	}

	public void setSumBenchPremium(Double sumBenchPremium) {
		this.sumBenchPremium = sumBenchPremium;
	}

	public Double getDiscount() {
		return discount;
	}

	public void setDiscount(Double discount) {
		this.discount = discount;
	}

	public Double getSumPremium() {
		return sumPremium;
	}

	public void setSumPremium(Double sumPremium) {
		this.sumPremium = sumPremium;
	}

	public Double getSumNetPremium() {
		return sumNetPremium;
	}

	public void setSumNetPremium(Double sumNetPremium) {
		this.sumNetPremium = sumNetPremium;
	}

	public Double getSumTaxPremium() {
		return sumTaxPremium;
	}

	public void setSumTaxPremium(Double sumTaxPremium) {
		this.sumTaxPremium = sumTaxPremium;
	}

	public List<KindPO> getKinds() {
		return kinds;
	}

	public void setKinds(List<KindPO> kinds) {
		this.kinds = kinds;
	}

	public Integer getProposalCacheFlag() {
		return proposalCacheFlag;
	}

	public void setProposalCacheFlag(Integer proposalCacheFlag) {
		this.proposalCacheFlag = proposalCacheFlag;
	}

	public String getBiDemandNo() {
		return biDemandNo;
	}

	public void setBiDemandNo(String biDemandNo) {
		this.biDemandNo = biDemandNo;
	}

	public String getBiDemandTime() {
		return biDemandTime;
	}

	public void setBiDemandTime(String biDemandTime) {
		this.biDemandTime = biDemandTime;
	}

	public Integer getNoDamYearsBI() {
		return noDamYearsBI;
	}

	public void setNoDamYearsBI(Integer noDamYearsBI) {
		this.noDamYearsBI = noDamYearsBI;
	}

	public Integer getLastDamagedBI() {
		return lastDamagedBI;
	}

	public void setLastDamagedBI(Integer lastDamagedBI) {
		this.lastDamagedBI = lastDamagedBI;
	}

	public Integer getThisDamagedBI() {
		return thisDamagedBI;
	}

	public void setThisDamagedBI(Integer thisDamagedBI) {
		this.thisDamagedBI = thisDamagedBI;
	}

	public Integer getLastDamagedCI() {
		return lastDamagedCI;
	}

	public void setLastDamagedCI(Integer lastDamagedCI) {
		this.lastDamagedCI = lastDamagedCI;
	}
	public String getStrSumBenchPremium() {
		return strSumBenchPremium;
	}

	public void setStrSumBenchPremium(String strSumBenchPremium) {
		this.strSumBenchPremium = strSumBenchPremium;
	}

	public String getStrSumPremium() {
		return strSumPremium;
	}

	public void setStrSumPremium(String strSumPremium) {
		this.strSumPremium = strSumPremium;
	}

	public String getStrSumNetPremium() {
		return strSumNetPremium;
	}

	public void setStrSumNetPremium(String strSumNetPremium) {
		this.strSumNetPremium = strSumNetPremium;
	}

	public String getStrSumTaxPremium() {
		return strSumTaxPremium;
	}

	public void setStrSumTaxPremium(String strSumTaxPremium) {
		this.strSumTaxPremium = strSumTaxPremium;
	}
	
	public List<PrpCprofitFactors> getFactors() {
		return factors;
	}

	public void setFactors(List<PrpCprofitFactors> factors) {
		this.factors = factors;
	}

	public void parser(Element doc) {
		kinds = Optional.ofNullable(kinds).orElse(Lists.newArrayList());
		Stream.of("itemKindMain", "itemKindSub", "itemKindSpecial").forEach(id -> {
			Element element = doc.getElementById(id);
			if (element != null) {
				Elements elements = element.select("tbody>tr");
				elements.forEach(e -> {
					if(e.select("input[id$=chooseFlag]").hasAttr("checked")) {
						KindPO itemPO = new KindPO();
						JsoupUtil.newInstance().parse(e, itemPO);
						kinds.add(itemPO);
					}
				});
			}
		});
	}
}
